home *** CD-ROM | disk | FTP | other *** search
- Imports StormSource.Gps
-
- Public Class NewWaypointForm
-
- ' Stores information about a GPS device
- Private WithEvents pDevice As Device
-
- ' Returns/sets the device containing waypoint information
- Public Property Device() As Device
- Get
- Return pDevice
- End Get
- Set(ByVal Value As Device)
- ' Remember the waypoint for editing later on
- pDevice = Value
-
- ' Populate the combo box with the list of available waypoint symbols
- WaypointSymbolComboBox.Items.Clear()
- WaypointSymbolComboBox.Items.AddRange(pDevice.GetSymbols)
- WaypointSymbolComboBox.SelectedIndex = WaypointSymbolComboBox.FindString("Dot")
-
- ' Populate the color combo box with the list of available waypoint symbols
- WaypointColorComboBox.Items.Clear()
- WaypointColorComboBox.Items.AddRange(pDevice.GetColors)
- WaypointColorComboBox.SelectedIndex = WaypointColorComboBox.FindString("Default")
-
- ' Populate the display mode box with the list of available waypoint symbols
- WaypointDisplayModeComboBox.Items.Clear()
- WaypointDisplayModeComboBox.Items.AddRange(pDevice.GetDisplayModes)
- WaypointDisplayModeComboBox.SelectedIndex = WaypointDisplayModeComboBox.FindString("SymbolOnly")
-
- ' Now, enable/disable features based on the capabilities of the device
- Description.Enabled = pDevice.SupportsWaypointComment
- Address.Enabled = pDevice.SupportsWaypointAddress
- WaypointSymbolComboBox.Enabled = pDevice.SupportsWaypointSymbol
- WaypointColorComboBox.Enabled = pDevice.SupportsWaypointColor
- WaypointDisplayModeComboBox.Enabled = pDevice.SupportsWaypointDisplayMode
- Facility.Enabled = pDevice.SupportsWaypointFacility
- Address.Enabled = pDevice.SupportsWaypointAddress
- City.Enabled = pDevice.SupportsWaypointCity
- State.Enabled = pDevice.SupportsWaypointState
- Country.Enabled = pDevice.SupportsWaypointCountry
- IntersectingRoad.Enabled = pDevice.SupportsWaypointIntersectingRoad
- End Set
- End Property
-
- Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
- Dim NewWaypoint As Waypoint
- ' Now set the waypoint's properties
- Try
- ' Create a new waypoint
- NewWaypoint = New Waypoint()
- ' Update the waypoint with values from the form
- NewWaypoint.Name = Me.WaypointName.Text
- ' Update the position
- Dim NewPosition As Position = StormSource.Gps.Position.Parse(Position.Text)
- NewWaypoint.Latitude = NewPosition.Latitude
- NewWaypoint.Longitude = NewPosition.Longitude
- ' Update the comment
- NewWaypoint.Description = Me.Description.Text
- ' Update the symbol
- NewWaypoint.Symbol = System.Enum.Parse(GetType(WaypointSymbol), WaypointSymbolComboBox.Text)
- ' Update the color
- NewWaypoint.Color = System.Enum.Parse(GetType(WaypointColor), WaypointColorComboBox.Text)
- ' Update the symbol
- NewWaypoint.DisplayMode = System.Enum.Parse(GetType(WaypointDisplayMode), WaypointDisplayModeComboBox.Text)
- ' Update the altitude
- Dim NewAltitude As Distance = Distance.Parse(Me.Altitude.Text)
- NewWaypoint.Altitude = NewAltitude
- ' Update the depth
- Dim NewDepth As Distance = Distance.Parse(Me.Depth.Text)
- NewWaypoint.Depth = NewDepth
- ' Update the facility
- NewWaypoint.Facility = Me.Facility.Text
- ' Update the address
- NewWaypoint.Address = Me.Address.Text
- NewWaypoint.City = Me.City.Text
- NewWaypoint.State = Me.State.Text
- NewWaypoint.Country = Me.Country.Text
- ' Update the intersecting road/intersection
- NewWaypoint.IntersectingRoad = Me.IntersectingRoad.Text
- Catch ex As Exception
- ' Some error occurred while try to update waypoint information
- MessageBox.Show(ex.Message, "Form Information is Invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- Exit Sub
- End Try
- Try
- ' Tell the waypoint which kind of GPS device to use
- NewWaypoint.Device = Me.Device
- ' Save this waypoint to the device
- NewWaypoint.Save()
- ' Refresh the waypoints collection
- NewWaypoint.Device.Receiver.Waypoints.Refresh()
- ' And unload this form
- Close()
- Catch ex As Exception
- ' Notify of the problem saving the waypoint
- MessageBox.Show(ex.Message, "Unable to Create Waypoint", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
- Exit Sub
- End Try
- End Sub
-
- ' Raised when editing of a waypoint has been cancelled
- Private Sub btnCancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelButton.Click
- Close()
- End Sub
-
- ' Raised when the device becomes identified
- Private Sub pDevice_DeviceIdentified(ByVal sender As Object, ByVal e As StormSource.Gps.DeviceEventArgs) Handles pDevice.DeviceIdentified
- Me.Device = e.Device
- End Sub
-
- End Class
-